package com.kp.fintech.admin.config;


import com.kp.fintech.admin.intercepter.UserContextInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;


@Configuration
@EnableWebMvc
public class CommonConfiguration implements WebMvcConfigurer {

    /**
     * 提前new出拦截器UserContextInterceptor，防止redis在拦截器中调用抛出空指针
     * @return UserContextInterceptor
     */
    @Bean
    public UserContextInterceptor getUserContextInterceptor(){
        return new UserContextInterceptor();
    }

    /**
     * 增加请求拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getUserContextInterceptor())
                .addPathPatterns("/**")       //添加所需要拦截的接口，这里我们拦截所有,但是
                .excludePathPatterns("/login/**"); //不拦截登陆和退出请求
    }

}
